package com.ysd.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ysd.qxgl.dao.IUsersDao;
import com.ysd.qxgl.dto.UsersDTO;
import com.ysd.qxgl.model.Users;
import com.ysd.qxgl.service.IUsersService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;



@RestController
@RequestMapping("/users")
public class UsersController {

    @Resource
    private IUsersDao usersDao;
    @Resource
    private IUsersService usersService;
    @ApiOperation(value = "查询所有用户",notes = "查询所有用户")
    @GetMapping
    public Map<String,Object> findAll(){
        List<Users> list=usersService.findAll();
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "多条件分页查询",notes = "多条件分页查询")
    @PostMapping("/findAllDTO")
    public Map<String ,Object> findAllDTO(@RequestBody UsersDTO dto){
        List<Users> list=usersService.findAllDTO(dto);
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @PostMapping("/addUser")
    public int addUser(@RequestBody Users user){
        return usersService.addUser(user);
    }
    @ApiOperation(value = "修改用户信息",notes = "修改用户信息")
    @PutMapping("/editUser")
    public int editUser(@RequestBody Users users){
        return usersService.editUser(users);
    }
    @ApiOperation(value = "删除用户",notes = "删除用户")
    @DeleteMapping("/delete/{id}")
    public int delUser(@PathVariable String id){
        return usersService.delUsers(id);
    } 
    @ApiOperation(value = "重置用户密码",notes = "重置用户密码")
    @PutMapping("/resetUserPassWord/{id}")
    public int resetUserPassWord(@PathVariable String id){
        return usersService.resetPassWord(id);
    }
    @ApiOperation(value = "锁定用户",notes = "锁定用户")
    @PutMapping("/lockedUser/{id}")
    public int lockedUser(@PathVariable String id){
        return usersService.lockedUser(id);
    }
    @ApiOperation(value = "解锁用户",notes = "解锁用户")
    @PutMapping("/unLockedUser/{id}")
    public int unLockedUser(@PathVariable String id){
        return usersService.unLockedUser(id);
    }
    @ApiOperation(value = "用户登录",notes = "用户登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "login_name",value = "用户登录名",required = true,paramType = "path"),
        @ApiImplicitParam(name = "password",value = "用户登录密码",required = true,paramType = "path")
    })
    @GetMapping("/login/{login_name}/{password}")
    public Users login(@PathVariable String login_name,@PathVariable String password){
        return usersService.login(login_name, password);
    }
}